import GlobalEvent from "../../Global/GlobalEvent";
import goldManager from "../goldManager";

//英雄生命值升级管理器
class healthUp {
    private static instance: healthUp;
    private lv: number = 1;
    private addGold: number = 50;
    private addHealth: number = 50;
    private bool = true;

    private constructor() {
        //从服务器获取用户存储的lv值 更新lv


        //购买的金币 * 购买等级
        this.addGold = this.lv * 50;
        //购买的攻击力 * 购买等级
        this.addHealth *= this.lv;
    }

    public static getInstance(): healthUp {
        if (!healthUp.instance) {
            healthUp.instance = new healthUp();
        }
        return healthUp.instance;
    }

    public upLv() {
        this.lv++;
    }

    public addgold(): number {
        this.addGold = this.lv * 50;
        return this.addGold;
    }

    public getlv(): number {
        return this.lv;
    }

    public addhealth(): number {
        if (this.lv % 10 === 0) {
            let lv2 = this.lv / 2;
            this.addHealth = this.lv / 2
        }
        console.log('商城生命值 = ',this.addHealth);
        
        return this.addHealth;
    }
    // 如果玩家的金币小于等于0或者小于所需金币，禁用按钮
    public getHealthbool() {
        let goldMana = goldManager.getInstance();
        // console.log('现在的金币 = ', goldMana.getGold());
        // console.log('购买所需的金币 = ', this.addGold);

        if (goldMana.getGold() <= 0 || goldMana.getGold() < this.addGold) {
            this.bool = false;
            GlobalEvent.emit('getHealthBoolean', this.bool);
            return;
        } else if (goldMana.getGold() >= this.addGold) {
            // 否则，激活按钮
            this.bool = true;
            GlobalEvent.emit('getHealthBoolean', this.bool); 
            return;

        }

    }

}
export default healthUp;